import time
import traceback
import urllib3
import requests
from jsonpath import jsonpath

from Common.DataHandle import ReRun
from Common.FontColor import outcome
from Common.MyUnit import MyTest
from Common.ReadYaml import ConfigYaml
from Common.Route import Any_Path
from ERP.goods.Public import GoodsRelatedData
good = GoodsRelatedData()
urllib3.disable_warnings()

class management_goods(MyTest):
    '''
    采购需求管理
    '''


    @ReRun(MyTest.setUp)
    def test_queryParameter_list(self):
       '''
       case1搜索创品数据是否同步至备货参数管理列表
       :param self:
       :return:
       '''
       product_info = GoodsRelatedData().product_publish()
       spu_code = product_info[1]['basic']['code']
       try:
           url = ConfigYaml("domain_name").base_url + self.url.format(spu_code)
           time.sleep(5)
           r = requests.get(url, headers=self.headers, stream=True, verify=False)
           result = r.json()
           if result['data']['total'] == 1:
               self.time = r.elapsed.total_seconds()
               self.result = {"success": True}
           else:
               self.result = {"success": False}
       except:
           self.singular = str(traceback.format_exc())
           outcome('red', self.singular)
           return self.singular


    # @ReRun(MyTest.setUp)
    # def test_reviewStatus_0(self):
    #     """
    #     case2同步数据至待检核列表验证，recommendations：系统建议量；targetInventory：目标库存
    #     finalConfirmation：最终确认量；supplemented：应补量；inventoryAvailable：可用库存
    #     """
    #     parameter = GoodsRelatedData().updateParameter(replenishmentType='0')   # 编辑备货参数
    #     sku_code = parameter['skuCode']
    #     res = GoodsRelatedData().job_to_requisition_review(jobid='23')  # 执行定时任务
    #     # reviewStatus = 0
    #     url = ConfigYaml("domain_name").base_url + self.url.format(sku_code)
    #     try:
    #         time.sleep(120)
    #         r=requests.get(url, headers=self.headers, stream=True, verify=False)  # 搜索sku
    #         result = r.json()
    #         # recommendations = result['data']['list'][0]['recommendations']
    #         targetInventory = result['data']['list'][0]['targetInventory']
    #         # finalConfirmation = result['data']['list'][0]['finalConfirmation']
    #         supplemented = result['data']['list'][0]['supplemented']
    #         inventoryAvailable = result['data']['list'][0]['inventoryAvailable']
    #         # 应补量 = 目标库存 - 可用库存
    #         num = supplemented - (targetInventory - inventoryAvailable)
    #         if num != 0:
    #             self.result = {"success": False}
    #         else:
    #             self.time = r.elapsed.total_seconds()
    #             self.result = {"success": True}
    #     except:
    #         self.singular = str(traceback.format_exc())
    #         outcome('red', self.singular)
    #         return self.singular

    # @ReRun(MyTest.setUp)
    # def test_submit_to_Review(self):
    #     """
    #     case3待检核工作台提交数据至已检核未调整验证
    #     :return:
    #     """
    #     requisition_review = GoodsRelatedData().submitRequisitionReview()
    #     finalConfirmation = requisition_review[1][0]['finalConfirmation']
    #     sku = requisition_review[0]
    #     url = ConfigYaml("domain_name").base_url + self.url
    #     self.data['skuCodes'] = sku
    #     try:
    #         r = requests.get(url, headers=self.headers, params=self.data, stream=True, verify=False)
    #         result = r.json()
    #         # 待检核中的需求确认量 = 已检核未调整中的需求确认量
    #         final = result['data']['list'][0]['finalConfirmation']
    #         num = final - finalConfirmation
    #         if num == 0:
    #             self.time = r.elapsed.total_seconds()
    #             self.result = {"success": True}
    #         else:
    #             self.result = {"success": False}
    #     except:
    #         self.singular = str(traceback.format_exc())
    #         outcome('red', self.singular)
    #         return self.singular


    # @ReRun(MyTest.setUp)
    # def test_submit_to_Review2(self):
    #     """
    #     case4未检核工作台同步数据至已检核已调整验证
    #     reviewStatus=2表示已检核已调整
    #     :return:
    #     """
    #     requisition_review = GoodsRelatedData().submitRequisitionReview(5)
    #     finalConfirmation = requisition_review[1][0]['finalConfirmation']
    #     sku = requisition_review[0]
    #     url = ConfigYaml("domain_name").base_url + self.url
    #     self.data['skuCodes'] = sku
    #     self.data['reviewStatus'] = 2
    #     try:
    #         r = requests.get(url, headers=self.headers, params=self.data, stream=True, verify=False)
    #         result = r.json()
    #         # 原确认需求量 + 需增加的量 = 修改后的确认需求量
    #         final = result['data']['list'][0]['finalConfirmation']
    #         num = final - finalConfirmation
    #         if num == 0:
    #             self.time = r.elapsed.total_seconds()
    #             self.result = {"success": True}
    #         else:
    #             self.result = {"success": False}
    #     except:
    #         self.singular = str(traceback.format_exc())
    #         outcome('red', self.singular)
    #         return self.singular

    @ReRun(MyTest.setUp)
    def test_purchase_list(self):
        """
        case5查询采购需求列表
        """
        try:
            r = GoodsRelatedData().purchase_list()
            self.result = r.json()
            self.time = r.elapsed.total_seconds()
        except:
            self.singular = str(traceback.format_exc())
            outcome('red', self.singular)
            return self.singular

    @ReRun(MyTest.setUp)
    def test_replenishment_export(self):
        """
        case6备货参数列表按品类导出，导出数量不能操作1万条，所以选择的是固定品类
        :return:
        """

        url = ConfigYaml("domain_name").base_url + self.url
        try:
            r = requests.get(url, headers=self.headers, stream=True, verify=False)
            content = r.content
            path = Any_Path("Export", "replenishment_export.xlsx")
            with open(path, 'wb') as f:
                f.write(content)
                f.close()
            if content:
                self.result = {"success": True}
            else:
                self.result = {"success": False, "msg": "全部订单全量导出错误..."}

            self.time = r.elapsed.total_seconds()
        except:
            self.singular = str(traceback.format_exc())
            outcome('red', self.singular)
            return self.singular

    @ReRun(MyTest.setUp)
    def test_replenishment_export_by_sku(self):
        """
        case7备货参数列表按sku导出，
        :return:
        """
        query_list = GoodsRelatedData().queryParameter()
        res = jsonpath(query_list, "$..'skuCode'")
        sku_codes = ','.join(res)
        url = ConfigYaml("domain_name").base_url + self.url
        self.data['skuCodes'] = sku_codes
        try:
            r = requests.get(url, headers=self.headers, params=self.data, stream=True, verify=False)
            content = r.content
            path = Any_Path("Export", "replenishment_export_by_sku.xlsx")
            with open(path, 'wb') as f:
                f.write(content)
                f.close()
            if content:
                self.result = {"success": True}
            else:
                self.result = {"success": False, "msg": "全部订单全量导出错误..."}

            self.time = r.elapsed.total_seconds()
        except:
            self.singular = str(traceback.format_exc())
            outcome('red', self.singular)
            return self.singular

    @ReRun(MyTest.setUp)
    def test_replenishment_import(self):
        """
        case8备货参数导入验证
        """
        try:
            r = GoodsRelatedData().replenishment_import()
            self.result = r.json()
            self.time = r.elapsed.total_seconds()

        except:
            self.singular = str(traceback.format_exc())
            outcome('red', self.singular)
            return self.singular

    @ReRun(MyTest.setUp)
    def test_query_sourceType(self):
        """case9货源类型查询"""
        try:
            r = GoodsRelatedData().query_sourceType()
            self.result = r.json()
            self.time = r.elapsed.total_seconds()
        except:
            self.singular = str(traceback.format_exc())
            outcome('red', self.singular)
            return self.singular
    '''
    @ReRun(MyTest.setUp)
    def test_supplier_sku_relation(self):
        """
        case10供货关系是否同步至备货参数管理
        主要验证供应商的交期
        验证前需要执行sql_insert_supplier()方法去操作数据库
        """
        res_sku = GoodsRelatedData().sql_insert_supplier()
        url = ConfigYaml("domain_name").base_url + self.url
        self.data['skuCodes'] = res_sku
        try:
            r = requests.get(url, headers=self.headers, params=self.data, stream=True, verify=False)
            result = r.json()
            deliveryDay=result['data']['list'][0]['deliveryDay']
            if deliveryDay == 5:
                self.time = r.elapsed.total_seconds()
                self.result = {"success": True}
            else:
                self.result = {"success": False}
        except:
            self.singular = str(traceback.format_exc())
            outcome('red', self.singular)
            return self.singular
    '''
    '''
    @ReRun(MyTest.setUp)
    def test_inventory(self):
        """
        case11库存信息是否至备货参数列表，方法执行前需要操作数据库insert_inventory_sql()
        """
        res = GoodsRelatedData().insert_inventory_sql()
        sku = res[0]
        # inventoryTotal表示入库前的库存总量
        inventoryTotal = res[1]
        url = ConfigYaml("domain_name").base_url + self.url
        self.data['skuCodes'] = sku
        try:
            r = requests.get(url, headers=self.headers, params=self.data, stream=True, verify=False)
            result = r.json()
            total_inventory = result['data']['list'][0]['inventoryTotal']
            total = total_inventory - inventoryTotal
            if total > 0:
                self.time = r.elapsed.total_seconds()
                self.result = {"success": True}
            else:
                self.result = {"success": False}
        except:
            self.singular = str(traceback.format_exc())
            outcome('red', self.singular)
            return self.singular
    '''

    @ReRun(MyTest.setUp)
    def test_order_by_replenishmentDays(self):
        """case12 备货参数列表，按备货天数倒序排序
           replenishmentDays: 备货天数
        """
        r = GoodsRelatedData().order_by_method("replenishmentDays")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        first = res['data']['list'][0]['replenishmentDays']
        second = res['data']['list'][1]['replenishmentDays']
        if first >= second:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_order_by_minFlowDays(self):
        """case13 备货参数列表，按最小周转天数倒序排序
           minFlowDays：最小周转天数
        """
        r = GoodsRelatedData().order_by_method("minFlowDays")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        first = res['data']['list'][0]['minFlowDays']
        second = res['data']['list'][1]['minFlowDays']
        if first >= second:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_order_by_securityDays(self):
        """case14 备货参数列表，按安全天数倒序排序
           securityDays：安全天数
        """
        r = GoodsRelatedData().order_by_method("securityDays")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        first = res['data']['list'][0]['securityDays']
        second = res['data']['list'][1]['securityDays']
        if first >= second:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_order_by_targetInventory(self):
        """case15 备货参数列表，按目标库存倒序排序
           targetInventory：目标库存
        """
        r = GoodsRelatedData().order_by_method("targetInventory")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        first = res['data']['list'][0]['targetInventory']
        second = res['data']['list'][1]['targetInventory']
        if first >= second:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_order_by_reorderPoint(self):
        """case16 备货参数列表，按再订货点倒序排序
           reorderPoint：再订货点
        """
        r = GoodsRelatedData().order_by_method("reorderPoint")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        first = res['data']['list'][0]['reorderPoint']
        second = res['data']['list'][1]['reorderPoint']
        if first >= second:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_order_by_averageQty(self):
        """case17 备货参数列表，按最小日均销量倒序排序
           averageQty：最小日均销量
        """
        r = GoodsRelatedData().order_by_method("averageQty")
        print(r[0].json())
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        first = res['data']['list'][0]['averageQty']
        second = res['data']['list'][1]['averageQty']
        if first >= second:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_order_by_notShippedQuantity(self):
        """case18 备货参数列表，按未发货数量倒序排序
           notShippedQuantity：未发货数量
        """
        r = GoodsRelatedData().order_by_method("notShippedQuantity")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        first = res['data']['list'][0]['notShippedQuantity']
        second = res['data']['list'][1]['notShippedQuantity']
        if first >= second:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_order_by_inventoryTotal(self):
        """case19 备货参数列表，按库存总量倒序排序
           inventoryTotal：库存总量
        """
        r = GoodsRelatedData().order_by_method("inventoryTotal")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        first = res['data']['list'][0]['inventoryTotal']
        second = res['data']['list'][1]['inventoryTotal']
        if first >= second:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_order_by_beginningPeriodInventoryAvailable(self):
        """case20 备货参数列表，按期初可用库存倒序排序
           beginningPeriodInventoryAvailable：期初可用库存
        """
        r = GoodsRelatedData().order_by_method("beginningPeriodInventoryAvailable")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        first = res['data']['list'][0]['beginningPeriodInventoryAvailable']
        second = res['data']['list'][1]['beginningPeriodInventoryAvailable']
        if first >= second:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_order_by_intransitTotal(self):
        """case21 备货参数列表，按在途数量倒序排序
           intransitTotal：在途数量
        """
        r = GoodsRelatedData().order_by_method("intransitTotal")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        first = res['data']['list'][0]['intransitTotal']
        second = res['data']['list'][1]['intransitTotal']
        if first >= second:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_order_by_beginningPeriodMerchantableDays(self):
        """case21 备货参数列表，按期初预计可销售天数倒序排序
           beginningPeriodMerchantableDays：期初预计可销售天数
        """
        r = GoodsRelatedData().order_by_method("beginningPeriodMerchantableDays")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        first = res['data']['list'][0]['beginningPeriodMerchantableDays']
        second = res['data']['list'][1]['beginningPeriodMerchantableDays']
        if first >= second:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_purchaseSaleStatus_normal(self):
        """case22 备货参数列表，购销状态为正常销售
           purchaseSaleStatus(3)：表示正常销售
        """
        r = GoodsRelatedData().purchaseSaleStatus(3)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        res['data']['list'][0]['purchaseSaleStatus']
        if res['data']['list'][0]['purchaseSaleStatus'] == "正常销售":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_purchaseSaleStatus_temp(self):
        """case23 备货参数列表，购销状态为临时缺货
           purchaseSaleStatus(5)：表示临时缺货
        """
        r = GoodsRelatedData().purchaseSaleStatus(5)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        res['data']['list'][0]['purchaseSaleStatus']
        if res['data']['list'][0]['purchaseSaleStatus'] == "临时缺货":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_purchaseSaleStatus_temp(self):
        """case24 备货参数列表，购销状态为停售
           purchaseSaleStatus(1)：表示停售
        """
        r = GoodsRelatedData().purchaseSaleStatus(1)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        res['data']['list'][0]['purchaseSaleStatus']
        if res['data']['list'][0]['purchaseSaleStatus'] == "停售":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_purchaseSaleStatus_temp(self):
        """case25 备货参数列表，购销状态为停售清仓
           purchaseSaleStatus(2)：表示停售清仓
        """
        r = GoodsRelatedData().purchaseSaleStatus(2)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        res['data']['list'][0]['purchaseSaleStatus']
        if res['data']['list'][0]['purchaseSaleStatus'] == "停售清仓":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_producName(self):
        """case26 备货参数列表，产品名称查询
           beihuo_query：备货参数列表
           productName="test" 按产品名称查询
        """
        r = GoodsRelatedData().beihuo_query(productName="test")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        result_str = res['data']['list'][0]['productName']
        if "test" in result_str or "TEST" in result_str:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}



    @ReRun(MyTest.setUp)
    def test_search_spu(self):
        """case27 备货参数列表，spu查询
           beihuo_query：备货参数列表
           spuCode=spu 按spu查询
        """
        prod = good.plm_list().json()
        spu = prod['data']['list'][0]['code']
        r = good.beihuo_query(spuCode=spu)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        code = res['data']['list'][0]['skuCode']
        if spu in code:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}


    @ReRun(MyTest.setUp)
    def test_search_sku(self):
        """case28 备货参数列表，sku查询
           beihuo_query：备货参数列表
           skuCode=sku 按sku查询
        """
        prod = good.plm_list().json()
        sku = prod['data']['list'][0]['skuListVos'][0]['skuCode']
        r = good.beihuo_query(skuCodes=sku)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        code = res['data']['list'][0]['skuCode']
        if sku == code:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_sourceType_pro(self):
        """case29 备货参数列表，货源类型-按预售查询
           beihuo_query：备货参数列表
          sourceType=0 按预售查询
        """
        r = good.beihuo_query(sourceType=0)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        sourceType = res['data']['list'][0]['sourceType']
        if sourceType == "预售":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_sourceType_online(self):
        """case30 备货参数列表，货源类型-按线上现货查询
           beihuo_query：备货参数列表
          sourceType=1 按线上现货查询
        """
        r = good.beihuo_query(sourceType=1)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        sourceType = res['data']['list'][0]['sourceType']
        if sourceType == "线上现货":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_sourceType_online(self):
        """case31 备货参数列表，货源类型-按供应商推品查询
           beihuo_query：备货参数列表
          sourceType=2 按供应商推品查询
        """
        r = good.beihuo_query(sourceType=2)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        sourceType = res['data']['list'][0]['sourceType']
        if sourceType == "供应商推品":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_sourceType_dev(self):
        """case32 备货参数列表，货源类型-按自主开发查询
           beihuo_query：备货参数列表
          sourceType=3 按自主开发查询
        """
        r = good.beihuo_query(sourceType=3)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        sourceType = res['data']['list'][0]['sourceType']
        if sourceType == "自主开发":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_plmCategory(self):
        """case33 备货参数列表，货商品品类查询
           beihuo_query：备货参数列表
          plmCategoryIds 货商品品类查询
        """
        category_list = good.get_category_list()
        r = good.beihuo_query(plmCategoryIds=category_list)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        categoryName = res['data']['list'][0]['categoryName']
        if "自动化专属" in categoryName:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_brandNames(self):
        """case34 备货参数列表，按品牌查询
           beihuo_query：备货参数列表
          brandNames 品牌
        """
        r = good.beihuo_query(brandNames="VIVAIA")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        brandNames = res['data']['list'][0]['brandName']
        if brandNames=="VIVAIA":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_riskType_wu(self):
        """case35 备货参数列表，按侵权等级无风险排序
           beihuo_query：备货参数列表
          riskType=0 按侵权等级无风险排序
        """
        r = good.beihuo_query(riskType=0)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        areaRisk = res['data']['list'][0]['areaRisk']
        if "无风险" in areaRisk:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_riskType_di(self):
        """case36 备货参数列表，按侵权等级低风险排序
           beihuo_query：备货参数列表
          riskType=1 按侵权等级低风险排序
        """
        r = good.beihuo_query(riskType=1)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        areaRisk = res['data']['list'][0]['areaRisk']
        if "低风险" in areaRisk:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_riskType_zhong(self):
        """case37 备货参数列表，按侵权等级中风险排序
           beihuo_query：备货参数列表
          riskType=2 按侵权等级中风险排序
        """
        r = good.beihuo_query(riskType=2)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        areaRisk = res['data']['list'][0]['areaRisk']
        if "中风险" in areaRisk:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_riskType_gao(self):
        """case38 备货参数列表，按侵权等级高风险排序
           beihuo_query：备货参数列表
          riskType=3 按侵权等级高风险排序
        """
        r = good.beihuo_query(riskType=3)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        areaRisk = res['data']['list'][0]['areaRisk']
        if "高风险" in areaRisk:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_riskType_gao(self):
        """case39 备货参数列表，按默认供应商搜索
           beihuo_query：备货参数列表
          supplierIds 按默认供应商搜索
          依赖供应商列表get_supplier()
        """
        supplier_name = ConfigYaml("supplier_name").base_config
        sup_info = good.get_supplier(name=supplier_name)
        supplierId = sup_info['supplierId']
        r = good.beihuo_query(supplierIds=supplierId)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        defaultSupplierName = res['data']['list'][0]['defaultSupplierName']
        if supplier_name == defaultSupplierName:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_replenishmentType(self):
        """case40 备货参数列表，按备货类型-不备货搜索
           beihuo_query：备货参数列表
          replenishmentType=0 不备货
        """
        r = good.beihuo_query(replenishmentType=0)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        re_type = res['data']['list'][0]['replenishmentType']
        if re_type ==0:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_replenishmentType_jing(self):
        """case41 备货参数列表，按备货类型-静态备货搜索
           beihuo_query：备货参数列表
          replenishmentType=1 静态备货
        """
        r = good.beihuo_query(replenishmentType=1)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        re_type = res['data']['list'][0]['replenishmentType']
        if re_type == 1:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_replenishmentType_dong(self):
        """case42 备货参数列表，按备货类型-动态备货搜索
           beihuo_query：备货参数列表
          replenishmentType=2 动态备货
        """
        r = good.beihuo_query(replenishmentType=2)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        re_type = res['data']['list'][0]['replenishmentType']
        if re_type == 2:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_supplierType_ODM(self):
        """case43 备货参数列表，按供应商类型-现货供应商搜索
           beihuo_query：备货参数列表
          supplierCategories=0 ODM现货供应商
        """
        r = good.beihuo_query(supplierCategories=0)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        odm = res['data']['list'][0]['defaultSupplierCategory']
        if odm == "现货供应商":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_supplierType_OEM(self):
        """case44 备货参数列表，按供应商类型-生产供应商搜索
           beihuo_query：备货参数列表
          supplierCategories=1 OEM生产供应商
        """
        r = good.beihuo_query(supplierCategories=1)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        oem = res['data']['list'][0]['defaultSupplierCategory']
        if oem == "生产供应商":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_supplierType_other(self):
        """case45 备货参数列表，按供应商类型-其他供应商搜索
           beihuo_query：备货参数列表
          supplierCategories=2 其他供应商
        """
        r = good.beihuo_query(supplierCategories=2)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        other = res['data']['list'][0]['defaultSupplierCategory']
        if other == "其他供应商":
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_choseByNames(self):
        """case46 备货参数列表，按供应商类型-按选品人搜索
           beihuo_query：备货参数列表
          choseByNames 选品人
        """
        user = good.chooser_list()
        r = good.beihuo_query(choseByNames=user)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        # name = res['data']['list'][0]['choseByName']
        name_list = jsonpath(res, "$..list[*].choseByName")
        if "任涛" in name_list or "补旭东" in name_list or "周荣" in name_list or "范天俊" in name_list:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_owner(self):
        """case47 备货参数列表，按供应商类型-按归属人搜索
           beihuo_query：备货参数列表
          owner 归属人
        """
        user = good.owner_list()
        r = good.beihuo_query(ownerNames=user)
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        # name = res['data']['list'][0]['choseByName']
        name_list = jsonpath(res, "$..list[*].ownerName")
        if "任涛" in name_list or "补旭东" in name_list or "范天俊" in name_list:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_search_updateUser(self):
        """case48 备货参数列表，按供应商类型-按修改人搜索
           beihuo_query：备货参数列表
          updatedByName 归属人
        """
        r = good.beihuo_query(updatedByName="范天俊")
        self.url = r[1]
        self.data = r[2]
        res = r[0].json()
        name = res['data']['list'][0]['updatedByName']
        if  "范天俊" in name:
            self.time = r[0].elapsed.total_seconds()
            self.result = {"success": True}
        else:
            self.result = {"success": False}

    @ReRun(MyTest.setUp)
    def test_purchaseSaleStatus_stop(self):
        '''
        case49 备货参数列表，购销状态为停售
        '''
        try:
 
            self.url = ConfigYaml(self.projectName).base_url + self.url
            r = requests.get(self.url, headers=self.headers, json=self.data, stream=True, verify=False)
            self.result = r.json()

            self.time = r.elapsed.total_seconds()
        except:
            self.singular = str(traceback.format_exc())
            outcome('red', self.singular)
            return self.singular


    # @ReRun(MyTest.setUp)
    # def test_intransit(self):
    #     """case50 在途数据验证，验证前需要执行sql（insert_sku_intransit_sql）"""
    #     pda = good.insert_sku_intransit_sql()
    #     sku = pda[1]
    #     intransitTotal = pda[2]
    #     r = good.beihuo_query(skuCodes=sku)
    #     self.url = r[1]
    #     self.data = r[2]
    #     res = r[0].json()
    #     total = res['data']['list'][0]['intransitTotal']
    #     if total - intransitTotal == 10:
    #         self.time = r[0].elapsed.total_seconds()
    #         self.result = {"success": True}
    #     else:
    #         self.result = {"success": False}
